<template>
	<view class="privacyAgreement">
		<view class="content" v-html="petTeacher"></view>
	</view>
</template>

<script setup lang="ts">
	import { onLoad } from '@dcloudio/uni-app'
	import { ref  } from 'vue'
	import api from '@/api'
	onLoad(() => {
		getPrivacyInfo()
	})
	const petTeacher = ref('')
	const getPrivacyInfo = async () => {
		const res : any = await api({
			method: 'get',
			// url: `/mall/user/getContent`
			url:'/mall/content/backend-configs/getHomeConfig'
		})
		// petTeacher.value = res.data.privacy_policy
		petTeacher.value = res.data['xjs.content.contentConfig.petsitterServiceAgreement'].replace(/(\<img|\<video|\<iframe|\<\/iframe>)/gi, function ($0, $1) {
			return {
				"<img": '<img style="width:100%;height:auto;display:block;" ',
				"<video": '<video style="max-width:100%;height:auto;" ',
				"<iframe": '<video style="max-width:100%;outline:none;" controls="controls"',
				"</iframe>": "</video>"
			}[$1];
		})
	}
	
	const handleRichText = (data) =>{
		if(!data) return data
		// 提取富文本中的文字
		data = data.replace(/<[^>]+>/g, "")
		// 去除特殊符号
		data = escape2Html(data)
		return data
	}
	
	//转意符换成普通字符
	const escape2Html = (str) => {
		var arrEntities = {
			'lt': '<',
			'gt': '>',
			'nbsp': ' ',
			'amp': '&',
			'quot': '"'
		};
		return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) {
			return arrEntities[t];
		})
	}
	
</script>

<style lang="scss" scoped>
.privacyAgreement{
	height: 100%;
	background-color: #F9F6F6;
	padding: 32rpx;
	.content{
		image{
			width: 100%;
		}
		video{
			width: 100%;
		}
	}
}	
</style>